﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Xml.Schema;
using System.Xml.XPath;
using 第一题;
using 第二题;

namespace 第五周作业
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            //第一题
            new t1();
            //第二题
            new t2();
        }
    }
}

namespace 第一题
{
    class t1
    {
        static t1()
        {
            //埃氏筛法选出[0,99]内的素数
            int[] prime = new int[100];
            for (int i = 2; i < 100; i++) prime[i] = 1;
            for (int i = 2; i < 100; i++) {
                if (prime[i] == 1)
                    for (int j = 2 * i; j < 100; j += i) {
                        prime[j] = 0;
                    }
            }

            //穷举法选出[6,100]内所有偶数的两素数和
            for (int i = 6; i <= 100; i += 2) {
                for (int j = 2; j < i; j++)
                    if (prime[j] == 1)
                        for (int k = 2; k <= i - j; k++)
                            if (prime[k] == 1 && j <= k && (j + k) == i) {
                                Console.WriteLine("{0:d}={1:d}+{2:d}", i, j, k);
                                break;
                            }
            }
        }
    }
}

namespace 第二题
{
    class t2
    {
        static t2()
        {
            //随机生成[0,1000]内100个整数
            int[] l = new int[100];
            Random r = new Random();
            for (int i = 0; i < 100; i++) {
                l[i] = r.Next(1000);
            }

            Console.WriteLine("排序前：");
            foreach (var i in l) {
                Console.Write(i + " ");
            }

            //linq排序
            Console.WriteLine("\n排序后:");
            var query = from i in l orderby i descending select i;
            foreach (var i in query) {
                Console.Write(i + " ");
            }

            double avg = l.Average();
            int sum = l.Sum();
            Console.WriteLine("\n和为{0:d},平均值为{1:000.00}", sum, avg);
        }
    }
}